<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <WasmCopyAppZipToHelixTestDir>false</WasmCopyAppZipToHelixTestDir>
    <WasmMainJSPath>main.mjs</WasmMainJSPath>
  </PropertyGroup>

  <Target Name="CopyRelinkedPackage" AfterTargets="WasmBuildApp" DependsOnTargets="Build" Inputs="$(WasmAppDir)/_framework/dotnet.js;
          $(WasmAppDir)/_framework/dotnet.runtime.js;
          $(WasmAppDir)/_framework/dotnet.native.js;
          $(WasmAppDir)/_framework/dotnet.native.wasm;
          $(MicrosoftNetCoreAppRuntimePackNativeDir)/dotnet.d.ts;
          $(MicrosoftNetCoreAppRuntimePackNativeDir)/package.json;" Outputs="bin/dotnet-runtime/.npm-stamp">
    <ItemGroup>
      <NpmPackageFiles Include="$(WasmAppDir)/_framework/dotnet.js"/>
      <NpmPackageFiles Include="$(WasmAppDir)/_framework/dotnet.runtime.js"/>
      <NpmPackageFiles Include="$(WasmAppDir)/_framework/dotnet.native.js"/>
      <NpmPackageFiles Include="$(WasmAppDir)/_framework/dotnet.native.wasm"/>
      <NpmPackageFiles Include="$(MicrosoftNetCoreAppRuntimePackNativeDir)/dotnet.d.ts"/>
      <NpmPackageFiles Include="$(MicrosoftNetCoreAppRuntimePackNativeDir)/package.json"/>
    </ItemGroup>
    <Copy SourceFiles="@(NpmPackageFiles)" DestinationFolder="bin/dotnet-runtime" />
    <Touch Files="bin/dotnet-runtime/.npm-stamp" AlwaysCreate="true" />
  </Target>

  <Target Name="WebPack" AfterTargets="BuildSampleInTree" DependsOnTargets="CopyRelinkedPackage">
    <Exec Command="npm install" WorkingDirectory="$(MSBuildProjectDirectory)"/>
    <Exec Command="npm run webpack -- --env Configuration=$(Configuration) --env WasmAppDir=$(WasmAppDir)" WorkingDirectory="$(MSBuildProjectDirectory)"/>
  </Target>

  <Target Name="RunSample" DependsOnTargets="RunSampleWithNode" />

</Project>
